package com.web.base.user.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;
import com.web.base.user.message.OfficeUserRequest;
import com.web.base.user.message.OfficeUserResponse;
import com.web.base.user.model.OfficeUser;

/**
 * 部门－用户转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月16日
 */
public class OfficeUserConvertor
{
	private OfficeUserConvertor()
	{
	}
	
	public static OfficeUser toOfficeUser(OfficeUserRequest request)
	{
		if (request == null)
			return null;
		
		OfficeUser officeUser = new OfficeUser();
		officeUser.setOfficeId(request.getOfficeId());
		officeUser.setUserId(request.getUserId());
		officeUser.setRole(request.getRole());
		officeUser.setJoinDate(request.getJoinDate());
		officeUser.setAuth(request.getAuth());
		return officeUser;
	}
	
	public static OfficeUserResponse toResponse(OfficeUser officeUser)
	{
		if (officeUser == null)
			return null;
		
		OfficeUserResponse response = new OfficeUserResponse();
		response.setOfficeId(officeUser.getOfficeId());
		response.setUserId(officeUser.getUserId());
		response.setRole(officeUser.getRole());
		response.setJoinDate(officeUser.getJoinDate());
		response.setAuth(officeUser.getAuth());
		return response;
	}
	
	public static List<OfficeUserResponse> toResponse(List<OfficeUser> list)
	{
		List<OfficeUserResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (OfficeUser officeUser : list)
		{
			responseList.add(toResponse(officeUser));
		}
		return responseList;
	}
	
	public static Map<Integer, OfficeUserResponse> toResponse(Map<Integer, OfficeUser> map)
	{
		Map<Integer, OfficeUserResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, OfficeUser> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<OfficeUserResponse> toResponse(Page<OfficeUser> page)
	{
		if (page == null)
			return null;
		
		Page<OfficeUserResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
